﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="text" encoding="utf-8" omit-xml-declaration="yes" indent="no" cdata-section-elements="script"/>
  <xsl:template match="/">
    <xsl:variable name="q">"</xsl:variable>
    <xsl:for-each select="//div[@parseableControl = 'UpdatePanel']">
      <xsl:value-of select="preceding-sibling::node[@id]"/>
      <xsl:variable name="text">
        <xsl:call-template name="replace">
          <xsl:with-param name="text" select="."/>
          <xsl:with-param name="replace">
            <xsl:value-of select="$q"/>
          </xsl:with-param>
          <xsl:with-param name="by">
            <xsl:value-of select="concat('\', $q)"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat('{', $q, 'updatePanel', $q, ':{', $q, 'name', $q, ':', $q, @id, $q, ',', $q, 'html', $q, ':', $q, $text, $q, '}}')"/>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="replace">
    <xsl:param name="text" />
    <xsl:param name="replace" />
    <xsl:param name="by" />
    <xsl:choose>
      <xsl:when test="contains($text, $replace)">
        <xsl:value-of select="substring-before($text,$replace)" />
        <xsl:value-of select="$by" />
        <xsl:call-template name="replace">
          <xsl:with-param name="text"
          select="substring-after($text,$replace)" />
          <xsl:with-param name="replace" select="$replace" />
          <xsl:with-param name="by" select="$by" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
